﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Cfg;


    public class NHibernateHelper
    {
        private static  ISessionFactory _sessionFactory;
        public NHibernateHelper()
        {
            if (_sessionFactory==null)
            {
                _sessionFactory = GetSessionFactory();                
            }
        }
        private ISessionFactory GetSessionFactory()
        {
            try
            {
                return (new Configuration()).Configure().BuildSessionFactory();
            }
            catch
            {
                return null;
            }           
        }
        public ISession GetSession()
        {
            ISession session ;
            try
            {
                session= _sessionFactory.OpenSession();
            }catch
            {
                session = null;               
            }
            return session;
        }
    }

